import { createHashRouter, Navigate } from "react-router-dom";

import Home from "../pages/home"
import Order from "../pages/order"
import Shop from "../pages/shop"
import GoodsList from "../pages/goods/list"
import GoodsAdd from "../pages/goods/add"
import GoodsType from "../pages/goods/type"
import GoodsEdit from "../pages/goods/edit";
import AccountList from "../pages/account/list";
import AccountAdd from "../pages/account/add";
import AccountModify from "../pages/account/modify";
import AccountCenter from "../pages/account/center"
import SaleGoods from "../pages/sale/goods";
import SaleOrder from "../pages/sale/order";
import Login from "../pages/login";
import Layout from "../pages/layout";
import Error from "../pages/error";



const routes = [
    {
        path: '*',
        element: <Error />
    },
    {
        path: '/',
        element: <Navigate to='/login' />,
    },
    {
        path: '/login',
        element: <Login />
    },
    {
        path: '/home',
        loader: () => ({ title: '首页', key: '/home' }),
        element: <Layout />,
        children: [
            {
                loader: () => ({ key: '/home' }),
                index: true,
                element: <Home />
            }
        ]
    },
    {
        path: '/account',
        loader: () => ({ title: '账号管理', key: '/account1' }),
        element: <Layout />,
        children: [
            {
                index: true,
                loader: () => ({ title: '账号列表', key: '/account' }),
                element: <AccountList />
            },
            {
                path: '/account/add',
                loader: () => ({ title: '账号添加', key: '/account/add' }),
                element: <AccountAdd />
            },
            {
                path: '/account/modify',
                loader: () => ({ title: '密码修改', key: '/account/modify' }),
                element: <AccountModify />
            },
            {
                path: '/account/center',
                loader: () => ({ title: '用户中心', key: '/account/center' }),
                element: <AccountCenter />
            },

        ]
    },
    {
        path: '/goods',
        loader: () => ({ title: '商品管理', key: '/goods1' }),
        element: <Layout />,
        children: [
            {
                index: true,
                loader: () => ({ title: '商品列表', key: '/goods' }),
                element: <GoodsList />
            },
            {
                path: '/goods/add',
                loader: () => ({ title: '商品添加', key: '/goods/add' }),
                element: <GoodsAdd />
            },
            {
                path: '/goods/type',
                loader: () => ({ title: '商品分类', key: '/goods/type' }),
                element: <GoodsType />
            },
        ]
    },
    {
        path: '/goodsEdit',
        loader:()=>({title:'商品编辑',key:'/goodsEdit'}),
        element: <Layout />,
        children: [
            {
                loader:()=>({key:'/goodsEdit'}),
                index: true,
                element: <GoodsEdit />
            }
        ]
    },
    
    {
        path: '/order',
        loader: () => ({ title: '订单管理', key: '/order' }),
        element: <Layout />,
        children: [
            {
                loader: () => ({ key: '/order' }),
                index: true,
                element: <Order />
            }
        ]
    },
    {
        path: '/sale',
        loader: () => ({ title: '数据统计', key: '/sale1' }),
        element: <Layout />,
        children: [
            {
                index: true,
                loader: () => ({ title: '商品统计', key: '/sale' }),
                element: <SaleGoods />
            },
            {
                path: '/sale/order',
                loader: () => ({ title: '订单统计', key: '/sale/order' }),
                element: <SaleOrder />
            },
        ]
    },
    {
        path: '/shop',
        loader: () => ({ title: '店铺管理', key: '/shop' }),
        element: <Layout />,
        children: [
            {
                loader: () => ({ key: '/shop' }),
                index: true,
                element: <Shop />
            }
        ]
    },

];
const router = createHashRouter(routes);
export default router;